<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>component-4</title>
    <script type="text/javascript" src="../assets/js/vue-2.3.0.js"></script>
</head>

<body>
    <h1>组件-4标签</h1>
    <hr>
    <div id="app">
        <component :is="choose"></component>
        <button @click="chooseA">A</button>
        <button @click="chooseB">B</button>
        <button @click="chooseC">C</button>
        <component is="componentB"></component>        
    </div>
</body>
<script type="text/javascript">
    // 子组件写在父组件上方
    var componentA = {
        template: '<div>I\'m componentA</div>'
    }
    var componentB = {
        template: '<div>I\'m componentB</div>'
    }
    var componentC = {
        template: '<div>I\'m componentC</div>'
    }
    var app = new Vue({
        el: "#app",
        data: {
            choose:'componentA'
        },
        components: {
            "componentA": componentA,
            "componentB": componentB,
            "componentC": componentC
        },
        methods:{
            chooseA:function(){
                this.choose = 'componentA'
            },
            chooseB:function(){
                this.choose = 'componentB'
            },
            chooseC:function(){
                this.choose = 'componentC'
            }
        }
    })
</script>

</html>